
const express = require("express")
const Users = require("../models/Users")
const app = express()
const User = require('../service/login')



app.post("/login",async (req,res)=>{
    console.log(req.body)
    let result =await User.login(req.body.name,req.body.password)
    console.log(result);
    res.send(result)
})

app.post("/register",async(req,res)=>{
    // console.log(req.body)
    let result = await User.register(req.body.name,req.body.password)
    // console.log(result);
    res.send(result)
})
// User.aaa()
app.get("/user", async (req, res) => {
// <<<<<<< HEAD
    let result = await User.getUsers(req.query.pageNum, req.query.pageSize)
    console.log(result);
    res.send(result)
})
// 删除用户
app.get('/deleteuser',async (req, res) => {
    let result = await User.DeleteUser(req.query.id)
    console.log(result);
    res.send(result)
})

//添加
app.post('/addusers',async (req, res) => {
    console.log(req.body);
        let result = await User.addUsers(req.body.Username,req.body.name,req.body.mail,req.body.loginPwd)
        res.send(result)
})

//修改
app.get("/updatausers", async (req, res) => {
    // console.log(req.query);
    let result = await User.updataUsers(req.query.Username,req.query.name,req.query.mail,req.query.loginPwd,req.query.id)
    res.send(result)
})

//查询用户
app.get("/selectusers", async (req, res) => {
  
    console.log(req.query);
    let result  = await User.selectUsers(req.query.Username)
    res.send(result)
})

//根据 id 修改
app.get('/users/id', async (req, res) =>{

    console.log(req.query);
    let result = await User.getUsersById(req.query.id)
    res.send(result)
})
// =======
//     let result = await User.getUsers()
//     console.log(result);
//     res.send(result)
// })
// >>>>>>> origin/yh

module.exports = app;










